#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
using namespace std;
class Date
{
public:
    int _year;
    int _month;
    int _day;
public:
    Date(int year, int month, int day)
    {
        _year = year;
        _month = month;
        _day = day;
    }
    static int GetMonthDay(int year, int month)
    {
        int MonthDay[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
        if (month == 2 && ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)))
        {
            return 29;
        }
        else
        {
            return MonthDay[month];
        }
    }
    Date& operator+=(int day)
    {
        _day += day;
        while (_day > GetMonthDay(_year, _month))
        {
            _day -= GetMonthDay(_year, _month);
            ++_month;
            if (_month == 13)
            {
                ++_year;
                _month = 1;
            }
        }
        return *this;
    }

};
int main() {
    int m, year, month, day, addday;
    scanf("%d", &m);
    while (m--)
    {
        scanf("%d %d %d %d", &year, &month, &day, &addday);
        Date d1(year, month, day);
        d1 += addday;
        printf("%d-%.2d-%.2d\n", d1._year, d1._month, d1._day);
    }

}